#pragma once

#include "Poller.h"
#include "Timestamp.h"

#include <cstring>
#include <unistd.h>
#include<vector>
#include<sys/epoll.h>

class Channel;

class EpollPoller:public Poller
{
public:
    EpollPoller(EventLoop* loop);
    ~EpollPoller() override; //显式声明子类中的成员函数是重写父类中的虚函数

    // 重写基类Poller的抽象方法
    Timestamp poll(int timeoutMs,ChannelList* activeChannels) override;
    void removeChannel(Channel* channel) override;
    void updateChannel(Channel* channel) override;
private:
    static const int kInitEventListSize = 16;
    // 填写活跃链接
    void fillActiveChannels(int numEvents,ChannelList* activeChannels) const; 
    // 更新channel通道
    void update(int operation,Channel* channel);

    using EventList = std::vector<epoll_event>;
    int epollfd_;
    EventList events_;

};

